//
//  TypeCollectionViewCell.m
//  DolphinMusic
//
//  Created by dllo on 15/3/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "TypeCollectionViewCell.h"

@implementation TypeCollectionViewCell

- (void)dealloc
{
    [_coverImageView release];
    [_typeLabel release];
    [_type release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.coverImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.coverImageView];
        [_coverImageView release];
        
        self.typeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.typeLabel];
        [_typeLabel release];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
}

- (void)setType:(Type *)type
{
    if (_type != type) {
        [_type release];
        _type = [type retain];
    }
    
    CGFloat height = self.contentView.frame.size.height;
    CGFloat width = self.contentView.frame.size.width;
    self.coverImageView.frame = CGRectMake(0, 0, width, height * 3 / 4);
    [self.coverImageView setImageWithURL:[NSURL URLWithString:[self.type.cover_path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    
    self.typeLabel.frame = CGRectMake(0, height * 3 / 4, width, height / 4);
    self.typeLabel.text = self.type.tname;
    self.typeLabel.textAlignment = NSTextAlignmentCenter;
}



@end
